const user = require("../sql/user");
const sql = require("../sql/index");

module.exports = function(){
    return (req,res,next)=>{
        if(req.session.userid === req.query.id){
            sql.get(user, {userid: req.query.id}, data=>{
                if(data.length > 0){
                    res.send(JSON.stringify({
                        code:0,
                        msg:"获取成功",
                        data:data[0]
                    }));
                }else{
                    res.send(JSON.stringify({
                        code: 1,
                        msg: "用户信息不存在"
                    }));
                }
            })
        }else{
            res.send(JSON.stringify({
                code:0,
                msg:"登录信息失效"
            }));
        }
    }
}